<?php
$this->breadcrumbs=array(
	'Payouts'=>array('/payouts'),
	'Yearweek',
);?>
<h1><?php echo $this->id . '/' . $this->action->id; ?></h1>

<?php
if ( !isset($_GET['year']) ) {
  $p_year = date("Y"); 	
}
else  {
  $p_year = $_GET['year'];	
}

if ( !isset($_GET['week_no']) ) {
  $p_weekno = date("W"); 	
}
else  {
  $p_weekno = $_GET['week_no'];	
}

$target = Yii::app()->request->baseUrl . "/?r=Payouts/admin";
?>

<form method="post" action="<?php echo $target?>">
	
	Select Week:
	<select name="year">
		<?php 
		  $year_start = 2012;
          $year_now = date("Y");
          $year = $year_now;
		  while ( $year >= $year_start ) { 
		  	 if ( $year == $p_year) {?>		
		        <option value="<?php echo $year?>" selected="selected"> <?php echo $year?></option>
		     <?php } else { ?>
		     	<option value="<?php echo $year?>"> <?php echo $year?></option>
		     <?php } ?>
		<?php $year--; }?>
	</select>
	<select name="week_no">
		<?php 
		  $i=1;
		  $weeks_in_a_year = 52;
		  $week_now = date("W");
		  while ( $i <= $weeks_in_a_year ) {
		  	 
			 if ( $i < 10 ) 
			   $w = "0$i";
			 else 
			   $w = $i;
			 
		  	 $week_start = date('M d', strtotime($p_year."W".$w."1")); 
			 $week_end   = date('M d', strtotime($p_year."W".$w."7"));   
		  	 $label = "Week $w | $week_start  -  $week_end";
		  	 if ( $i == $p_weekno) {?>		
		        <option value="<?php echo $i?>" selected="selected"> <?php echo $label?></option>
		     <?php } else { ?>
		     	<option value="<?php echo $i?>"> <?php echo $label?></option> 
		     <?php } ?>
		<?php $i++; }?>
	</select>
	<input type="submit" value="Generate Payouts" />
</form>